/**
 * 统计页面中医馆js
 * @author lh
 * 2016-01-15
 *
 */
/**
 * 中医馆数据表格属性配置
 */
//设置表格数据的样式。高度和宽度，刷新页面，样式重新调整
$('#medicalTcmMuseum_eCharts').css('height',orange.mainPage.getHeight());
$('#medicalTcmMuseum_eCharts').css('width',orange.mainPage.getWidth());
function mtm_query(){
	$('#medicalTcmMuseum_Grid').datagrid({
		url:'s/orgRes/table',//+'/'+encodeURI(encodeURI("浙江省"))+'/'+encodeURI(encodeURI("杭州市"))+'/'+encodeURI(encodeURI("上城区")),
		queryParams:{
			province:$('#mtm_province').combobox('getText')=='全国'?'':$('#mtm_province').combobox('getText'),//'北京市',
			city:$('#mtm_city').combobox('getText')=='全省'?'':$('#mtm_city').combobox('getText'),//"北京市",
			dist:$('#mtm_district').combobox('getText')=='全市'?'':$('#mtm_district').combobox('getText')//"昌平区"
		},
		loadFilter:orange.systemPage.selfLoadFilter
	});
	mtm_reLoadOption();
}
	$('#medicalTcmMuseum_Grid').datagrid({ 
		url:'s/orgRes/table',
		queryParams:{
			province:'',
			city:"",
			dist:""
		},
	    singleSelect:true,
	    rownumbers:true,
	    columns:[[ 
	        {field:'guid',hidden:true},
	        {field:'orgName',title:'名称',width:'10%',sortable:true,halign:'center',formatter:mtm_checkDetail},
	        {field:'addressFull',title:'地址',width:'20%',sortable:true,halign:'center'}, 
	        {field:'orgArea',title:'面积（m²）',width:'10%',sortable:true,halign:'center'},
	        {field:'orgBedspace',title:'床位',width:'10%',sortable:true,halign:'center'},
	        {field:'doctorTcmc',title:'中医人数',width:'10%',sortable:true,halign:'center'},
	        {field:'doctorWest',title:'西医人数',width:'10%',sortable:true,halign:'center',formatter:mt_option}, 
	        {field:'techTotalc',title:'技师人数',width:'10%',sortable:true,halign:'center'},
	        {field:'foundedTime',title:'成立时间',width:'18%',sortable:true,halign:'center',formatter:mt_dateOption}
	    ]],
	    pagination:true,
	    sortable:true,
	    sortName: 'type',
	    sortOrder: 'asc',
	    onLoadSuccess:function(data){
	    	debugger;
	    }
	});
	function mt_option(value,rows){
		return (rows.doctorTotalc-rows.doctorTcmc);
	}
	function mt_dateOption(value,rows){
		return dateFormat.dateFormat(new Date(rows.foundedTime));
	}
	//grid link
	function mtm_checkDetail(value, row, index){
		//debugger;
		if(value==null){
			return null;
		}else{
			return '<a href="#" onclick="tcmReloadOrCreate(\''+row.guid+'\',\''+row.orgName+'\')">'+value+'</a>';	
		}
	};
	//查询条件combobox配置
	//省级数据
	var clearData=[];
	var pData=[{'id':1,'text':'全国'},{'id':2,'text':'北京市'},{'id':3,'text':'天津市'},{'id':4,'text':'河北省'}];
	$("#mtm_province").combobox({
		data:pData,   
	    valueField:'id',   
	    textField:'text',
	    onLoadSuccess:function(data){
	    	$("#mtm_province").combobox('setValue',data[0].id);
	    },
	    onSelect:function(node){
	    	if(node.id==1){
	    		$("#mtm_city").combobox({data:clearData});
	    		$("#mtm_district").combobox({data:clearData});
//	    		$("#mtm_city + .combo").hide();
//	    		$("#mtm_district + .combo").hide();
	    	}else{
	    		$("#mtm_city").combobox({data:cData});
//	    		$("#mtm_city + .combo").show();
	    	}
	    }
	});//市级数据
	var cData=[{'id':1,'text':'全省'},{'id':2,'text':'北京市'},{'id':3,'text':'天津市'}
	,{'id':4,'text':'石家庄市'}];
	$("#mtm_city").combobox({
//		data:cData,   
	    valueField:'id',   
	    textField:'text',
	    onLoadSuccess:function(data){
//	    	$("#mtm_city").combobox('setValue',data[0].id);
	    },
	    onSelect:function(node){
	    	if(node.id==1){
	    		$("#mtm_district").combobox({data:clearData});
//	    		$("#mtm_district + .combo").hide();
	    	}else{
	    		$("#mtm_district").combobox({data:tData});
//	    		$("#mtm_district + .combo").show();
	    	}
	    } 
	});
	//区域数据
	var tData=[{'id':1,'text':'全市'},{'id':2,'text':'西区'},{'id':3,'text':'东区'},{'id':4,'text':'北区'}];
	$("#mtm_district").combobox({
//		data:tData,  
	    valueField:'id',   
	    textField:'text' ,
	    onLoadSuccess:function(data){
//	    	$("#mtm_district").combobox('setValue',data[0].id);
	    }
	});
	//echarts图表配置
	//页面初始化加载
	$.ajax({
        url:'s/chartOrg',//+encodeURI(encodeURI("北京市"))+'/'+encodeURI(encodeURI("北京市"))+'/'+encodeURI(encodeURI("东城区")),
        type: 'post',
        data:{
			province:'',
			city:'',
			dist:''
		},
        success: function(data) {
        	var initData=eval(data);
        	var myChart = echarts.init($("#medicalTcmMuseum_eCharts")[0]);
        	var seriesData1=[];//纵轴数据
        	var xData=[];//横轴数据
        	if(data!=""){
        		for (var i=0;i<initData.length;i++){
            		xData.push(initData[i].period);
            		seriesData1.push(initData[i].docTotal);
            	}
        	}
        	mtm_eChart_option(xData,seriesData1,myChart);
        }
    });
	//ajax请求，加载数据
    // 指定图表的配置项和数据
	function mtm_eChart_option(xData,seriesData1,myChart){
		option = {
				grid:{
					show:false,
					bottom :'15%',
					top:'25%',
					height:'65%',
					width:'85%',
					left:'7%',
					right:'8%'
				},
			    tooltip : {
			        trigger: 'axis'
			    },
			    legend: {
			        data:['中医馆数量'],
			        top:'8%'
			    },
			    calculable : true,
			    xAxis : [
			        {
			            type : 'category',
			            boundaryGap : false, 
			            data : xData//['2013-04','2013-07','2013-10','2014-01','2014-07','2014-10','2015-01','2015-04','2015-07','2015-10','2016-01']
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'中医馆数量',
			            type:'line',
			            data:seriesData1
			        }
			    ]
			};
		    // 使用刚指定的配置项和数据显示图表。
		    myChart.setOption(option);
	}
	function mtm_reLoadOption(){
		$.ajax({
	        url:'s/chartOrg',//+encodeURI(encodeURI("北京市"))+'/'+encodeURI(encodeURI("北京市"))+'/'+encodeURI(encodeURI("东城区")),
	        type: 'post',
	        data:{
	        	province:$('#mtm_province').combobox('getText')=='全国'?'':$('#mtm_province').combobox('getText'),//'北京市',
    			city:$('#mtm_city').combobox('getText')=='全省'?'':$('#mtm_city').combobox('getText'),//"北京市",
    			dist:$('#mtm_district').combobox('getText')=='全市'?'':$('#mtm_district').combobox('getText')//"昌平区"
			},
	        success: function(data) {
	        	var initData=eval(data);
	        	var myChart = echarts.init($("#medicalTcmMuseum_eCharts")[0]);
	        	var seriesData1=[];//纵轴数据
	        	var xData=[];//横轴数据
	        	for (var i=0;i<initData.length;i++){
	        		xData.push(initData[i].period);
	        		seriesData1.push(initData[i].docTotal);
	        	}
	        	mtm_eChart_option(xData,seriesData1,myChart);
	        }
	    });
	}
	
	